# encoding=utf8
'''
Created on Dec 28, 2015

@author: jingyang <jingyang@smalltreemedia.com>
'''
from django.db import models

from app_info.models import PLATFORM


STATUS = (
    ('A', 'Active'),
    ('D', 'Deactive'),
)


class SDKInfo(models.Model):
    title = models.CharField('Title', max_length=200)
    platform = models.CharField('Platform', max_length=1, choices=PLATFORM,
                                default='I')
    desc = models.TextField('Description', null=True, blank=True)
    status = models.CharField('Status', max_length=1, choices=STATUS,
                              default='D')
    created_at = models.DateTimeField('Created At', auto_now_add=True)

    def __unicode__(self):
        return self.title

    class Meta:
        verbose_name = 'SDK Info'
        verbose_name_plural = verbose_name
        ordering = ('status',)


class SDKVersion(models.Model):
    sdk_info = models.ForeignKey(SDKInfo, verbose_name='SDK Info')
    code = models.CharField('Version Code', max_length=200)
    desc = models.TextField('Description / Change Log', null=True, blank=True)
    status = models.CharField('Status', max_length=1, choices=STATUS,
                              default='D')
    created_at = models.DateTimeField('Created At', auto_now_add=True)

    def __unicode__(self):
        return '{}: {}'.format(self.sdk_info, self.code)

    class Meta:
        verbose_name = 'SDK Version'
        verbose_name_plural = verbose_name
        ordering = ('sdk_info', '-created_at')
